import loadmap
import hiker

rawmapfile = input("Put in the name of the map file:")
themap = loadmap.maploader(rawmapfile)

#Draws a small map around the starting location
# R = Ravine, F = Field, H = Hill, M = Mountain, C = Cliff
def quickmap():
	td = { 0:'R', 1:'F', 2:'H', 3:'M', 4:'C'} 
	for i in range(30 , -31, -1):
		s = ""
		for j in range(-30 , 31):
			c = td[themap[j,i][0]]
			if [i,j] == [0,0]:
				c = " "
			s += c
		print s


def run(days, h):
	while(days>0):
		while(h.current_steps < h.max_steps):
			h.choose_the_way()
			if not h.alive:
#				print "Dirtnap"
#				h.printStats()
				return [0, h.location]
			if h.location == [0,0]:
#				print "Returned"
#				h.printStats()
				return [1, [0,0]]
		h.drink()
		days -=1
		h.current_steps = 0
#	print "Time ran out"
#	h.printStats()
	return [2, h.location]

#experience, maxsteps, maxwater, maxsenseofdirection, badluck
experienced = [1,30,5,.5,.0001]
novice = [0,20,3,.5,.001]
starts = [[-15,0],[-10,5],[-5,10],[0,15],[5,10],[10,5],[15,0],[10,-5],[5,-10],[0,-15],[-5,-10],[-10,-5]]

def simulate(statz , days, num_hikers, starting_location):
	#Run statistics:
	num_dead = 0
	locations = []
	num_timeout = 0
	num_returned = 0
	
	for i in xrange(num_hikers):
		
		h = hiker.Hiker(themap, statz)
		h.location = starting_location
		stat = run(days, h)
		locations.append(stat[1])
		if stat[0] == 0:
			num_dead+=1
		elif stat[0] == 1:
			num_returned+=1
		elif stat[0] == 2:
			num_timeout+=1
	
	print "Returned:",num_returned
	print "Timed out:", num_timeout
	print "Dead:", num_dead
#	print "Locations of the various hikers:"
#	print locations



def simulate2(statz , days, num_hikers, starting_location):
	#Run statistics:
	num_dead = 0
	locations = []
	num_timeout = 0
	num_returned = 0
	
	for i in xrange(num_hikers):
		
		h = hiker.Hiker(themap, statz)
		h.location = starting_location
		stat = run(days, h)
		locations.append(stat[1])
		if stat[0] == 0:
			num_dead+=1
		elif stat[0] == 1:
			num_returned+=1
		elif stat[0] == 2:
			num_timeout+=1
	
	return [num_returned, num_timeout, num_dead]

mass_stats_experienced = [0,0,0]
mass_stats_novice = [0,0,0]

for s in starts:
	exp_stats = simulate2(experienced, 7, 1000, s)
	nov_stats = simulate2(novice, 7, 1000, s)
	mass_stats_experienced[0] += exp_stats[0]
	mass_stats_experienced[1] += exp_stats[1]
	mass_stats_experienced[2] += exp_stats[2]
	mass_stats_novice[0] += nov_stats[0]
	mass_stats_novice[1] += nov_stats[1]
	mass_stats_novice[2] += nov_stats[2]
print
print
print "Experienced Mass Stats:"
print "Returned:", mass_stats_experienced[0]
print "Timed out:",mass_stats_experienced[1]
print "Dead:", mass_stats_experienced[2]

print
print "Novice Mass Stats:"
print "Returned:", mass_stats_novice[0]
print "Timed out:",mass_stats_novice[1]
print "Dead:", mass_stats_novice[2]

